import {
  SysCustomWidgetType,
  SysOnlineFormType,
  OnlineFormEventType,
} from '@/common/staticDict/index';
import { ANY_OBJECT } from '@/types/generic';

const input = {
  span: {
    name: '组件宽度',
    widgetType: SysCustomWidgetType.Slider,
    value: 12,
    visible: function (formConfig: ANY_OBJECT) {
      return (
        formConfig &&
        formConfig.form.formType !== SysOnlineFormType.QUERY &&
        formConfig.activeMode === 'pc'
      );
    },
    disabled: false,
    min: 1,
    max: 24,
  },
  type: {
    name: '输入框类型',
    value: 'text',
    widgetType: SysCustomWidgetType.Select,
    dropdownList: function (formConfig: ANY_OBJECT) {
      if (formConfig && formConfig.activeMode === 'mobile') {
        return [
          {
            id: 'text',
            name: '单行文本',
          },
          {
            id: 'textarea',
            name: '多行文本',
          },
          {
            id: 'digit',
            name: '整数',
          },
          {
            id: 'number',
            name: '数字',
          },
          {
            id: 'tel',
            name: '手机号',
          },
          {
            id: 'password',
            name: '密码',
          },
        ];
      } else {
        return [
          {
            id: 'text',
            name: '单行文本',
          },
          {
            id: 'textarea',
            name: '多行文本',
          },
        ];
      }
    },
  },
  placeholder: {
    name: '占位文本',
    widgetType: SysCustomWidgetType.Input,
    value: '',
  },
  'show-password': {
    name: '是否密码',
    value: false,
    widgetType: SysCustomWidgetType.Switch,
    dropdownList: [
      {
        id: true,
        name: '是',
      },
      {
        id: false,
        name: '否',
      },
    ],
  },
  // Jie. 20250417 增加自动高度，默认行数
  autosize: {
    name: '自动高度',
    value: true,
    widgetType: SysCustomWidgetType.Switch,
    visible: function (form: ANY_OBJECT) {
      const widget = form.currentWidget;
      return !!widget && !!widget.props && widget.props.type === 'textarea';
    },
    dropdownList: [
      {
        id: true,
        name: '是',
      },
      {
        id: false,
        name: '否',
      },
    ],
  },
  rows: {
    name: '默认行数',
    widgetType: SysCustomWidgetType.NumberInput,
    value: 3,
    visible: function (form: ANY_OBJECT) {
      const widget = form.currentWidget;
      return !!widget && !!widget.props && widget.props.type === 'textarea';
    },
  },
  'show-word-limit': {
    name: '是否显示字数统计',
    value: false,
    widgetType: SysCustomWidgetType.Switch,
    dropdownList: [
      {
        id: true,
        name: '必填',
      },
      {
        id: false,
        name: '非必填',
      },
    ],
  },
  maxlength: {
    name: '最大字符数',
    widgetType: SysCustomWidgetType.NumberInput,
    value: undefined,
  },
  required: {
    name: '是否必填',
    value: false,
    widgetType: SysCustomWidgetType.Switch,
    dropdownList: [
      {
        id: true,
        name: '必填',
      },
      {
        id: false,
        name: '非必填',
      },
    ],
  },
  disabled: {
    name: '是否禁用',
    value: false,
    visible: function (formConfig: ANY_OBJECT) {
      return (
        formConfig &&
        (formConfig.form.formType !== SysOnlineFormType.QUERY || formConfig.activeMode === 'mobile')
      );
    },
    widgetType: SysCustomWidgetType.Switch,
    dropdownList: [
      {
        id: false,
        name: '启用',
      },
      {
        id: true,
        name: '禁用',
      },
    ],
  },
  readonly: {
    name: '是否只读',
    value: false,
    visible: function (formConfig: ANY_OBJECT) {
      return formConfig && formConfig.activeMode === 'mobile';
    },
    widgetType: SysCustomWidgetType.Switch,
    dropdownList: [
      {
        id: true,
        name: '只读',
      },
      {
        id: false,
        name: '非只读',
      },
    ],
  },
};

const inputConfig = {
  widgetType: SysCustomWidgetType.Input,
  icon: 'online-icon icon-input',
  attribute: input,
  allowEventList: [
    OnlineFormEventType.CHANGE,
    OnlineFormEventType.BLUR,
    OnlineFormEventType.FOCUS,
    OnlineFormEventType.DISABLE,
    OnlineFormEventType.VISIBLE,
  ],
  supportBindTable: true,
  supportBindColumn: true,
};

export default inputConfig;
